Skip to content

Rework initialization and accessor generation#143

Open
nbdd0121 wants to merge 5 commits into
mainfrom
dev/accessor-rework
Open

Rework initialization and accessor generation#143
nbdd0121 wants to merge 5 commits into
mainfrom
dev/accessor-rework

Conversation

@nbdd0121
Copy link
Copy Markdown
Member

Depends on #132

Use different guard types to determine the type of let bindings generated, and also move much of the logic of the generated code to __internal.rs. Each commit explains the rationale on its own.

@nbdd0121 nbdd0121 force-pushed the dev/accessor-rework branch from 7407d8b to a91a85e Compare April 28, 2026 15:44
@nbdd0121 nbdd0121 mentioned this pull request May 4, 2026
@nbdd0121 nbdd0121 force-pushed the dev/accessor-rework branch 2 times, most recently from 6056cad to 5f615ef Compare May 14, 2026 15:24
nbdd0121 added 3 commits May 14, 2026 20:33
`InitializerKind::Code` is a special case where it does not initialize a
field, and thus generate no guard and accessors. Handle it earlier and make
the rest of the code more linear.

Signed-off-by: Gary Guo <gary@garyguo.net>
Instead of projecting the created reference, simply create drop guards with
different marker types and have the `let_binding()` method of guards of
different marker produce different type instead.

This allows more flexible lifetime as this is now controlled by the guard.
This will be needed when implementing self-referential fields.

Signed-off-by: Gary Guo <gary@garyguo.net>
The `InitData` and `PinData` traits do not need to exist, the inference
helpers could be inherent methods instead.

There is no risk for calling the wrong methods even when user defines it,
as inherent methods take priority over trait methods.

With this change, it unlocks the possibility of attaching additional bounds
to the method per type, which is not possible for trait methods.

Signed-off-by: Gary Guo <gary@garyguo.net>
@nbdd0121 nbdd0121 force-pushed the dev/accessor-rework branch 2 times, most recently from 29539e9 to 6816900 Compare May 14, 2026 19:37
nbdd0121 added 2 commits May 14, 2026 20:40
By projecting slots, the `pin_init!` and `init!` code path can be more
unified. This also reduces the amount of macro-generated code and shifts
them to the shared infrastructure.

Signed-off-by: Gary Guo <gary@garyguo.net>
Instead of projecting using pointer to a field project the full slot. This
further shifts the code generation from the initializer site to the struct
definition site, which means less code is generated overall.

It also makes the safety comment easier to justify, as now the projection
is done by the `#[pin_data]` macro which has full visibility of pinnedness
of fields.

The field alignment could also be checked on the `#[pin_data]` side;
however, since `init!()` macro works for other type of structs, we cannot
remove the alignment check from `init!`/`pin_init!` side anyway, so I opted
to still keep the alignment check in init.rs.

Signed-off-by: Gary Guo <gary@garyguo.net>
@nbdd0121 nbdd0121 force-pushed the dev/accessor-rework branch from 6816900 to aa8b598 Compare May 14, 2026 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant